#include"threadPool.h"

int threadPoolInit(threadPool_t *threadPool, char *confFile){
    char str[128];
    unsigned long strSize = 128;
    // 连接Mysql
    int ret = getValInJSON("host", confFile, str, strSize);
    MYERROR_CHECK(ret, -1, "getValInJSON");
    char host[64] = {0};
    strncpy(host, str, strlen(str));
    ret = getValInJSON("user", confFile, str, strSize);
    MYERROR_CHECK(ret, -1, "getValInJSON");
    char user[64] = {0};
    strncpy(user, str, strlen(str));
    ret = getValInJSON("password", confFile, str, strSize);
    MYERROR_CHECK(ret, -1, "getValInJSON");
    char password[64] = {0};
    strncpy(password, str, strlen(str));
    ret = getValInJSON("database", confFile, str, strSize);
    MYERROR_CHECK(ret, -1, "getValInJSON");
    char database[64] = {0};
    strncpy(database, str, strlen(str));
    MYSQL *m_mysql;
    m_MysqlInit(&m_mysql, host, user, password, database);
    ret = getValInJSON("workerNum", confFile, str, strSize);
    MYERROR_CHECK(ret, -1, "getValInJSON");
    taskQueueInit(&threadPool->taskQueue);
    threadPool->threadNum=atoi(str);
    threadPool->tidArr=(pthread_t *)calloc(threadPool->threadNum,sizeof(pthread_t));
    threadPool->isexit=0;//退出标志位，运行为0，退出为1
    threadPool->mysql=m_mysql;
    printf("线程池初始化成功!!  工作线程数:%d\n",threadPool->threadNum);
    return 0;
}
